package com.huo.util;

import java.math.BigDecimal;

public class CountUtil {
	
	private static int FILE_UNIT_M = 1024*1024;
	
	private static int FILE_UNIT_K = 1024;

	public static long divide(long longNum,int intNum) {
		if(intNum != 0) {
			return new BigDecimal(longNum).divide(new BigDecimal(intNum)).longValue();
		}
		return 0;
	}
	
	/**
	 * 计算文件大小 返回M
	 * @param byteNum
	 * @return
	 */
	public static String countFileSize(long byteNum) {
		if(byteNum/FILE_UNIT_M > 0) {
			return byteNum/FILE_UNIT_M + "M";
		}
		if(byteNum/FILE_UNIT_K > 0) {
			return byteNum/FILE_UNIT_K + "K";
		}else {
			return byteNum + "B";
		}
		
	}
}
